<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css"  media="all">
  <link rel="stylesheet" href="__PUBLIC__/font-awesome/css/font-awesome.min.css" media="all" />
  <link rel="stylesheet" href="__CSS__/admin.css"  media="all">
</head>
<body style="padding:10px;">
  <div class="tplay-body-div">
    <div style="margin-top: 20px;">
    </div>
    <form class="layui-form" id="admin">
      <div class="layui-form-item">
        <label class="layui-form-label">物流公司</label>
        <div class="layui-input-inline">
          <select id="express_id" name="express_id" lay-search="">
            <option value="">物流公司</option>
            {volist name="$express" id="vo"}
            <option value="{$vo.express_id}">{$vo.express_company}</option>
            {/volist}
          </select>
        </div>
      </div>
      <input type="hidden" id="express_company" name="express_company">
      <div class="layui-form-item">
        <label class="layui-form-label">物流单号</label>
        <div class="layui-input-inline">
          <input name="express_no" lay-verify="" placeholder="请输入物流单号" autocomplete="off" class="layui-input" type="text">
        </div>
      </div>
      <input type="hidden" name="id" value="{$id}">
      <div class="layui-form-item">
        <div class="layui-input-block">
          <button class="layui-btn" lay-submit lay-filter="admin">立即提交</button>
          <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
      </div>

    </form>


    <script src="__PUBLIC__/layui/layui.js"></script>
    <script src="__PUBLIC__/jquery/jquery.min.js"></script>
    <script>
      // 监听select的change事件，将选中的company值赋给隐藏的input元素
      $('#express_id').change(function() {

        var selectedOption = $(this).find('option:selected');
        var selectedCompany = selectedOption.attr('data-company');
        $('#company').val(selectedCompany);
      });
    </script>
    <script>

        var message;
        layui.config({
            base: '__JS__/',
            version: '1.0.1'
        }).use(['app', 'message'], function() {
            var app = layui.app,
                $ = layui.jquery,
                layer = layui.layer;
            //将message设置为全局以便子页面调用
            message = layui.message;
            //主入口
            app.set({
                type: 'iframe'
            }).init();
        });
    </script>
    <script>
      layui.use(['layer', 'form'], function() {
          var layer = layui.layer,
              $ = layui.jquery,
              form = layui.form;
          $(window).on('load', function() {
              form.on('submit(admin)', function(data) {
                var express_company = $('#express_id').find("option:selected").text();
                $('#express_company').val(express_company);
                  $.ajax({
                      url:"{:url('admin/order/send_goods')}",
                      data:$('#admin').serialize(),
                      type:'post',
                      async: false,
                      success:function(res) {
                          if(res.code == 1) {
                              layer.alert(res.msg, function(index){
                                // location.href = res.url;
                                // window.close(); // 关闭页面
                                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                parent.location.reload();//刷新父页面，注意一定要在关闭当前iframe层之前执行刷新
                                parent.layer.close(index); //再执行关闭
                              })
                          } else {
                              layer.msg(res.msg);
                          }
                      }
                  })
                  return false;
              });
          });
      });
    </script>
  </div>
</body>
</html>